package com.chris.seata_stock.dubbo;

import com.alibaba.dubbo.config.annotation.Service;
import com.chris.seata_facade.StockFacade;
import com.chris.seata_stock.entity.StockPO;
import com.chris.seata_stock.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author wujf
 * @date 2022/1/19
 */
@Service
@Component
public class DubboStockService implements StockFacade {

    @Autowired
    private StockService stockService;

    @Override
    public boolean updateStock() {
        StockPO stockPO = new StockPO();
        stockPO.setProductId(1L);
        StockPO stock = stockService.getStock(stockPO);
        stock.setTotal(stock.getTotal() - 1);
        stock.setTotal(stock.getUsed() + 1);
        boolean b = stockService.updateStock(stock);
        return b;
    }
}
